export const state = () => ({
  token: null,
})
export const mutations = {
  setToken(state, token) {
    state.token = token
    this.$cookies.set('token', token)
  },
}
export const actions = {
  nuxtServerInit({ commit }, { req }) {
    console.log('初始化了>>>→➡️➡️➡️')
    if (req.headers.cookie) {
      const token = req.headers.cookie
        .split(';')
        .find((c) => c.trim().startsWith('token='))
      if (token) {
        commit('setToken', token.split('=')[1])
      }
    } else {
      console.log('没有cookie')
      commit('setToken', 'token-test-test-one')
    }
  },
}
